package com.yiwei.zxp.view;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.yiwei.zxp.Application;
import com.yiwei.zxp.R;
import com.yiwei.zxp.util.PreferenceUtils;
import com.yiwei.zxp.util.ToastUtil;
import com.yiwei.zxp.util.UI;
import com.yiwei.zxp.util.Util;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by xsooy-pc on 18-5-22.
 */

public class PacketPayFinishDilaog extends Dialog {


    @BindView(R.id.btn_cancel)
    ImageView btnCancel;
    @BindView(R.id.btn_phone)
    TextView btnPhone;
    @BindView(R.id.btn_submit)
    TextView btnSubmit;
    @BindView(R.id.edit_bank)
    EditText editBank;
    private Context context;


    public PacketPayFinishDilaog(Context context) {
        this(context, R.style.DialogStyle);
    }

    public PacketPayFinishDilaog(Context context, int themeResId) {
        super(context, themeResId);
        this.context = context;
        initView();
    }

    private void initView() {
        setContentView(R.layout.dialog_packet_pay_finish);
        ButterKnife.bind(this);
        setCancelable(false);

        Window mWindow = getWindow();
        WindowManager.LayoutParams lp = mWindow.getAttributes();
        lp.width = Util.getDisplayMetrics(context).widthPixels;
        lp.gravity = Gravity.BOTTOM;
        mWindow.setAttributes(lp);
        Util.setBankChange(editBank);
        btnPhone.setText(PreferenceUtils.getString(Application.getInstance(), "service_phone", ""));
    }


    private OnChooseListener onChooseListener;

    public PacketPayFinishDilaog setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
        return this;
    }

    @OnClick({R.id.btn_cancel, R.id.btn_phone, R.id.btn_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_cancel:
                dismiss();
                break;
            case R.id.btn_phone:
                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + PreferenceUtils.getString(Application.getInstance(), "service_phone", "")));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
                break;
            case R.id.btn_submit:
                if (TextUtils.isEmpty(UI.toString(editBank))) {
                    ToastUtil.makeText(context, "银行账号不能为空");
                    return;
                }
                if (onChooseListener != null) {
                    onChooseListener.onEditFinish(UI.toString(editBank));
                }
                dismiss();
                break;
        }
    }

    public interface OnChooseListener {
        void onEditFinish(String count);
    }
}
